﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity.ModelConfiguration;
using DomainClasses;
using System.ComponentModel.DataAnnotations.Schema;

namespace DataLayerFluent
{
	public class AliasConfiguration : EntityTypeConfiguration<Alias>
	{
		public AliasConfiguration()
		{
			HasKey( a => a.AuthorKey );
			Property( a => a.CreateData )
				.HasColumnName( "StartDate" )
				.HasColumnOrder( 1 )
				.HasColumnType( "date" )
				//.HasDatabaseGeneratedOption( DatabaseGeneratedOption.Computed ) // Seta um valor default ao Inserir na coluna.
				.IsRequired();
			Property( a => a.Name ).IsFixedLength().HasMaxLength( 40 );
			ToTable( "TwitterAliases" );
			HasRequired( a => a.Avatar ).WithRequiredPrincipal();
		}
	}

	public class TweetConfiguration : EntityTypeConfiguration<Tweet>
	{
		public TweetConfiguration()
		{
			HasRequired( t => t.Author ).WithMany( a => a.Tweets ).HasForeignKey( t => t.AuthorId ); // Essa configuração indica qual é o o nome da FK que será utilizada para o relacionamento.
		}
	}

	public class LongTweetConfiguration : EntityTypeConfiguration<LongTweet>
	{
		public LongTweetConfiguration()
		{
			Map<LongTweet>( m => m.ToTable( "LongTweets" ) );
		}
	}

	public class AvatarConfiguration : EntityTypeConfiguration<TwitterAvatar>
	{
		public AvatarConfiguration()
		{
			HasKey( a => a.AuthorKey );
			ToTable( "TwitterAliases" );
		}
	}
}
